package com.hengpeng.itfin.domain.draw.common;

import java.io.File;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class PayUtil
{

	private static final String datePattern = "yyyyMMddHHmmssSSS";

	private static final SimpleDateFormat sdf = new SimpleDateFormat(datePattern);

	public static String getCurrDate()
	{
		Date today = new Date();
		String todayAsString = sdf.format(today);
		return todayAsString;
	}

	/**
	 * 将流水号重新进行包装
	 * @param preFix
	 * @param seq
	 * @return
	 */
	public static String formatFlowId(String preFix, Integer seq)
	{
		StringBuffer seqBuf = new StringBuffer(String.valueOf(seq));
		int L = seqBuf.length();
		L = 12 - L;
		for (int i = 0; i < L; i++)
			seqBuf.insert(0, "0");
		seqBuf.insert(0, preFix);
		return seqBuf.toString();
	}

	/**
	 * 恒朋、瑞彩在支付宝的提现 扣除手续费处理 (0-5万元（不包含5万元）1元每笔； 5万元以上5元每笔)
	 * @param oldMoney 　原始提款金额　单位＂元＂
	 * @return　扣除手续费后的提款金额 单位＂元＂
	 */
	public static double recoup(double oldMoney)
	{
		double newMoney = 0;
		if (oldMoney > 0)
		{
			if (oldMoney < 50000)
			{
				newMoney = oldMoney - 1;
			}
			else if (oldMoney >= 50000)
			{
				newMoney = oldMoney - 5;
			}
		}
		else
		{
			newMoney = 0;
		}
		return newMoney;
	}

	/**
	 * 上海中心在支付宝的提现 扣除手续费处理 (0-2万元（不包含2万元）1元每笔；2-5万元 3元每笔; 5万元以上5元每笔)
	 * @param oldMoney 　原始提款金额　单位＂元＂
	 * @return　扣除手续费后的提款金额 单位＂元＂
	 */
	public static double recoup2(double oldMoney)
	{
		double newMoney = 0;
		if (oldMoney > 0)
		{
			if (oldMoney < 20000)
			{
				newMoney = oldMoney - 1;
			}
			else if ((oldMoney >= 20000) && (oldMoney < 50000))
			{
				newMoney = oldMoney - 3;
			}
			else if (oldMoney >= 50000)
			{
				newMoney = oldMoney - 5;
			}
		}
		else
		{
			newMoney = 0;
		}
		return newMoney;
	}

	/**
	 * <pre>
	 * 大于5W元才使用分行名称，否则分行名称设空
	 * 除了十三家直连银行不需要支行名称，其它银行都需要填写支行名称
	 * </pre>
	 * @param money 提现金额，单位＂元＂
	 * @param branch 　分行名称
	 * @return
	 */
	public static String recoupBankAddress(double money, String branch)
	{
		return branch;
		/*
		 * if (money >= 50000) { return branch; } return "";
		 */
	}

	/**
	 * <pre>
	 * ＂分＂转＂元＂
	 * &quot;元&quot;　精确到小数点后两位
	 * </pre>
	 * @param cent 　金额　单位：＂分＂
	 * @return
	 */
	public static double convertDollar(int cent)
	{
		DecimalFormat df = new DecimalFormat("#0.00");
		Double d = Double.valueOf(cent);
		return new Double(df.format(d / 100));
	}

	/**
	 * <pre>
	 * "元"　转　"分"
	 * </pre>
	 * @param dollar "元"
	 * @return
	 */
	public static int convertCent(Double dollar)
	{
		Double cent = dollar * 100;
		return cent.intValue();
	}

	/**
	 * <pre>
	 * 精确到小数点后两位(四舍五入)
	 * </pre>
	 * @param putvalue
	 * @return
	 */
	public static double formatDouble(double putvalue)
	{
		DecimalFormat df = new DecimalFormat("#0.00");
		return new Double(df.format(putvalue));
	}

	public static void main(String args[]) throws UnknownHostException
	{
		System.out.println(PayUtil.getCurrDate());
		System.out.println(PayUtil.formatDouble(PayUtil.recoup(PayUtil.convertDollar(101))));
		if (true)
			return;
		String path = "E:/te/memberstore/upload/t.txt";
		File f = new File(path);
		System.out.println(f.isAbsolute());
		System.out.println(f.exists());
		System.out.println(f.isDirectory());
		// System.out.println(f.mkdir());
		System.out.println(f.mkdirs());
		System.out.println(f.isAbsolute());
		System.out.println(f.exists());
		System.out.println(f.isDirectory());

		System.out.println(recoup(convertDollar(5999783)));
		System.out.println(convertCent(199.67));
		System.out.println(formatFlowId("999", 100));
	}

}
